function Druid_CheckForMissingRake()
	local x
	if # tblPGetMeleeEnemies > 0 then
		for x = 0, # tblPGetMeleeEnemies do
			local obj = tblPGetMeleeEnemies[x]
			if obj
			and obj:Exists()
			and Player:IsFacing(obj)
			then
				local vRake = select(8,obj:GetAura(ccrSpellIDtoSpellName(RAKE)))
				if (vRake == nil or vRake ~= "player") then
					return true
				else
					return false
				end
			end
		end
		return false
	else
		return false
	end					
end

function Druid_ApplyMissingRake()
	local x
	if # tblPGetMeleeEnemies > 0 then
		for x = 0, # tblPGetMeleeEnemies do
			local obj = tblPGetMeleeEnemies[x]
			if obj
			and obj:Exists()
			and Player:IsFacing(obj)
			and ccrSpellCanAttack(RAKE, obj)
			then
				local vRake = select(8, obj:GetAura(ccrSpellIDtoSpellName(RAKE)))
				if (vRake == nil or vRake ~= "player") then
					obj:CastSpellByName(GetSpellInfo(RAKE))
					return
				else
					return
				end
			end
		end
	else
		return
	end
	return
end

function Druid_CheckForMissingThrash(spec)
	local vThrash
	if spec == nil then
		if ccrPlayerSpec() == 2 then vThrash = THRASH_FERAL end
		if ccrPlayerSpec() == 3 then vThrash = THRASH_BEAR end
	else
		if spec == 2 then vThrash = THRASH_FERAL end
		if spec == 3 then vThrash = THRASH_BEAR end
	end
	local x
	if # tblPGetMeleeEnemies > 0 then
		for x = 0, # tblPGetMeleeEnemies do
			local obj = tblPGetMeleeEnemies[x]
			if obj
			and obj:Exists()
			then
			local vThrash = select(8, obj:GetAura(ccrSpellIDtoSpellName(vThrash)))
				if (vThrash == nil or vThrash ~= "player") then
					return true
				else
					return false
				end
			end
		end
		return false
	else
		return false
	end					
end

function Druid_ApplyMissingThrash(spec)
	local vThrash
	if spec == nil then
		if ccrPlayerSpec() == 2 then vThrash = THRASH_FERAL end
		if ccrPlayerSpec() == 3 then vThrash = THRASH_BEAR end
	else
		if spec == 2 then vThrash = THRASH_FERAL end
		if spec == 3 then vThrash = THRASH_BEAR end
	end
	ccrCast(vThrash)
	return
end

function Druid_Savage_Roar_Buff()
	if ccRS.Druid_2_UseSavagery
	and ccrPlayerHasSpell(SAVAGE_ROAR) 
	then
		if not ccR_DSRU then
			ccR_DSRU = CreateFrame("Frame");
			ccR_DSRU:RegisterEvent("PLAYER_TARGET_CHANGED")
			ccR_DSRU:SetScript("OnEvent", ccR_DSRU_OnEvent)
		end
	end
end

function ccR_DSRU_OnEvent(self, event, arg1)
	if ccRS.Druid_2_UseSavagery
	and event == "PLAYER_TARGET_CHANGED"
	and UnitCanAttack("player","target") == 1
	and ccrPlayerHasBuff(CAT_FORM)
	then
		ccR_Druid_Savage_Roar()
	end
end

function ccR_Druid_TwoThrash()
	tblCat = {}
	tblBear = {}
	local x
	if #tblPGetMeleeEnemies > 0 then
		for x = 0, #tblPGetMeleeEnemies do
			local obj = tblPGetMeleeEnemies[x]
			if obj
			and obj:Exists()
			then
				ClearUnitID("Thrash_Unit")
				obj:SetAsUnitID("Thrash_Unit")
				local i
				-- Find BEAR Thrash
				for i = 1, 40 do
					local vUnit = {UnitDebuff("Thrash_Unit", i)}
					if vUnit[1] ~= nil
					and vUnit[1] == "Thrash"
					and vUnit[8] == "player"
					then
						if vUnit[11] == THRASH_BEAR then
							table.insert(tblBear, "Moo Cow")
						end
						if vUnit[11] == THRASH_FERAL then
							table.insert(tblCat, "Moo Cow")
						end
					end
				end
			end
		end
		if #tblCat < #tblPGetMeleeEnemies then
			-- Apply Cat thrash
			if not ccrPlayerHasBuff(CAT_FORM) then ccrCast(CAT_FORM) end
			if ccrPlayerHasBuff(CAT_FORM) then
				ccrCast(THRASH_FERAL)
			end
		end
		if #tblBear < #tblPGetMeleeEnemies then
			-- Apply Bear thrash
			if not ccrPlayerHasBuff(BEAR_FORM) then ccrCast(BEAR_FORM) end
			if ccrPlayerHasBuff(BEAR_FORM) then
				ccrCast(THRASH_BEAR)
			end
		end
	end
end